package com.room.search.web.rest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import com.room.search.IntegrationTest;
import com.room.search.domain.RoomUserBrokerChantMessage;
import com.room.search.repository.RoomUserBrokerChantMessageRepository;
import com.room.search.service.dto.RoomUserBrokerChantMessageDTO;
import com.room.search.service.mapper.RoomUserBrokerChantMessageMapper;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
import javax.persistence.EntityManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;

/**
 * Integration tests for the {@link RoomUserBrokerChantMessageResource} REST controller.
 */
@IntegrationTest
@AutoConfigureMockMvc
@WithMockUser
class RoomUserBrokerChantMessageResourceIT {

    private static final String DEFAULT_MESSAGE = "AAAAAAAAAA";
    private static final String UPDATED_MESSAGE = "BBBBBBBBBB";

    private static final Integer DEFAULT_STATUS = 1;
    private static final Integer UPDATED_STATUS = 0;

    private static final String DEFAULT_MESSAGE_TYPE = "AAAAAAAAAA";
    private static final String UPDATED_MESSAGE_TYPE = "BBBBBBBBBB";

    private static final Long DEFAULT_SEND_ID = 1L;
    private static final Long UPDATED_SEND_ID = 2L;

    private static final Long DEFAULT_RECEIVE_ID = 1L;
    private static final Long UPDATED_RECEIVE_ID = 2L;

    private static final String DEFAULT_CREATED_BY = "AAAAAAAAAA";
    private static final String UPDATED_CREATED_BY = "BBBBBBBBBB";

    private static final Instant DEFAULT_CREATED_DATE = Instant.ofEpochMilli(0L);
    private static final Instant UPDATED_CREATED_DATE = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    private static final String DEFAULT_LAST_MODIFIED_BY = "AAAAAAAAAA";
    private static final String UPDATED_LAST_MODIFIED_BY = "BBBBBBBBBB";

    private static final Instant DEFAULT_LAST_MODIFIED_DATE = Instant.ofEpochMilli(0L);
    private static final Instant UPDATED_LAST_MODIFIED_DATE = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    private static final String ENTITY_API_URL = "/api/room-user-broker-chant-messages";
    private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}";

    private static Random random = new Random();
    private static AtomicLong count = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));

    @Autowired
    private RoomUserBrokerChantMessageRepository roomUserBrokerChantMessageRepository;

    @Autowired
    private RoomUserBrokerChantMessageMapper roomUserBrokerChantMessageMapper;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restRoomUserBrokerChantMessageMockMvc;

    private RoomUserBrokerChantMessage roomUserBrokerChantMessage;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static RoomUserBrokerChantMessage createEntity(EntityManager em) {
        RoomUserBrokerChantMessage roomUserBrokerChantMessage = new RoomUserBrokerChantMessage()
            .message(DEFAULT_MESSAGE)
            .status(DEFAULT_STATUS)
            .messageType(DEFAULT_MESSAGE_TYPE)
            .sendId(DEFAULT_SEND_ID)
            .receiveId(DEFAULT_RECEIVE_ID)
            .createdBy(DEFAULT_CREATED_BY)
            .createdDate(DEFAULT_CREATED_DATE)
            .lastModifiedBy(DEFAULT_LAST_MODIFIED_BY)
            .lastModifiedDate(DEFAULT_LAST_MODIFIED_DATE);
        return roomUserBrokerChantMessage;
    }

    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static RoomUserBrokerChantMessage createUpdatedEntity(EntityManager em) {
        RoomUserBrokerChantMessage roomUserBrokerChantMessage = new RoomUserBrokerChantMessage()
            .message(UPDATED_MESSAGE)
            .status(UPDATED_STATUS)
            .messageType(UPDATED_MESSAGE_TYPE)
            .sendId(UPDATED_SEND_ID)
            .receiveId(UPDATED_RECEIVE_ID)
            .createdBy(UPDATED_CREATED_BY)
            .createdDate(UPDATED_CREATED_DATE)
            .lastModifiedBy(UPDATED_LAST_MODIFIED_BY)
            .lastModifiedDate(UPDATED_LAST_MODIFIED_DATE);
        return roomUserBrokerChantMessage;
    }

    @BeforeEach
    public void initTest() {
        roomUserBrokerChantMessage = createEntity(em);
    }

    @Test
    @Transactional
    void createRoomUserBrokerChantMessage() throws Exception {
        int databaseSizeBeforeCreate = roomUserBrokerChantMessageRepository.findAll().size();
        // Create the RoomUserBrokerChantMessage
        RoomUserBrokerChantMessageDTO roomUserBrokerChantMessageDTO = roomUserBrokerChantMessageMapper.toDto(roomUserBrokerChantMessage);
        restRoomUserBrokerChantMessageMockMvc
            .perform(
                post(ENTITY_API_URL)
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomUserBrokerChantMessageDTO))
            )
            .andExpect(status().isCreated());

        // Validate the RoomUserBrokerChantMessage in the database
        List<RoomUserBrokerChantMessage> roomUserBrokerChantMessageList = roomUserBrokerChantMessageRepository.findAll();
        assertThat(roomUserBrokerChantMessageList).hasSize(databaseSizeBeforeCreate + 1);
        RoomUserBrokerChantMessage testRoomUserBrokerChantMessage = roomUserBrokerChantMessageList.get(
            roomUserBrokerChantMessageList.size() - 1
        );
        assertThat(testRoomUserBrokerChantMessage.getMessage()).isEqualTo(DEFAULT_MESSAGE);
        assertThat(testRoomUserBrokerChantMessage.getStatus()).isEqualTo(DEFAULT_STATUS);
        assertThat(testRoomUserBrokerChantMessage.getMessageType()).isEqualTo(DEFAULT_MESSAGE_TYPE);
        assertThat(testRoomUserBrokerChantMessage.getSendId()).isEqualTo(DEFAULT_SEND_ID);
        assertThat(testRoomUserBrokerChantMessage.getReceiveId()).isEqualTo(DEFAULT_RECEIVE_ID);
        assertThat(testRoomUserBrokerChantMessage.getCreatedBy()).isEqualTo(DEFAULT_CREATED_BY);
        assertThat(testRoomUserBrokerChantMessage.getCreatedDate()).isEqualTo(DEFAULT_CREATED_DATE);
        assertThat(testRoomUserBrokerChantMessage.getLastModifiedBy()).isEqualTo(DEFAULT_LAST_MODIFIED_BY);
        assertThat(testRoomUserBrokerChantMessage.getLastModifiedDate()).isEqualTo(DEFAULT_LAST_MODIFIED_DATE);
    }

    @Test
    @Transactional
    void createRoomUserBrokerChantMessageWithExistingId() throws Exception {
        // Create the RoomUserBrokerChantMessage with an existing ID
        roomUserBrokerChantMessage.setId(1L);
        RoomUserBrokerChantMessageDTO roomUserBrokerChantMessageDTO = roomUserBrokerChantMessageMapper.toDto(roomUserBrokerChantMessage);

        int databaseSizeBeforeCreate = roomUserBrokerChantMessageRepository.findAll().size();

        // An entity with an existing ID cannot be created, so this API call must fail
        restRoomUserBrokerChantMessageMockMvc
            .perform(
                post(ENTITY_API_URL)
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomUserBrokerChantMessageDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomUserBrokerChantMessage in the database
        List<RoomUserBrokerChantMessage> roomUserBrokerChantMessageList = roomUserBrokerChantMessageRepository.findAll();
        assertThat(roomUserBrokerChantMessageList).hasSize(databaseSizeBeforeCreate);
    }

    @Test
    @Transactional
    void getAllRoomUserBrokerChantMessages() throws Exception {
        // Initialize the database
        roomUserBrokerChantMessageRepository.saveAndFlush(roomUserBrokerChantMessage);

        // Get all the roomUserBrokerChantMessageList
        restRoomUserBrokerChantMessageMockMvc
            .perform(get(ENTITY_API_URL + "?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(roomUserBrokerChantMessage.getId().intValue())))
            .andExpect(jsonPath("$.[*].message").value(hasItem(DEFAULT_MESSAGE)))
            .andExpect(jsonPath("$.[*].status").value(hasItem(DEFAULT_STATUS)))
            .andExpect(jsonPath("$.[*].messageType").value(hasItem(DEFAULT_MESSAGE_TYPE)))
            .andExpect(jsonPath("$.[*].sendId").value(hasItem(DEFAULT_SEND_ID.intValue())))
            .andExpect(jsonPath("$.[*].receiveId").value(hasItem(DEFAULT_RECEIVE_ID.intValue())))
            .andExpect(jsonPath("$.[*].createdBy").value(hasItem(DEFAULT_CREATED_BY)))
            .andExpect(jsonPath("$.[*].createdDate").value(hasItem(DEFAULT_CREATED_DATE.toString())))
            .andExpect(jsonPath("$.[*].lastModifiedBy").value(hasItem(DEFAULT_LAST_MODIFIED_BY)))
            .andExpect(jsonPath("$.[*].lastModifiedDate").value(hasItem(DEFAULT_LAST_MODIFIED_DATE.toString())));
    }

    @Test
    @Transactional
    void getRoomUserBrokerChantMessage() throws Exception {
        // Initialize the database
        roomUserBrokerChantMessageRepository.saveAndFlush(roomUserBrokerChantMessage);

        // Get the roomUserBrokerChantMessage
        restRoomUserBrokerChantMessageMockMvc
            .perform(get(ENTITY_API_URL_ID, roomUserBrokerChantMessage.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(roomUserBrokerChantMessage.getId().intValue()))
            .andExpect(jsonPath("$.message").value(DEFAULT_MESSAGE))
            .andExpect(jsonPath("$.status").value(DEFAULT_STATUS))
            .andExpect(jsonPath("$.messageType").value(DEFAULT_MESSAGE_TYPE))
            .andExpect(jsonPath("$.sendId").value(DEFAULT_SEND_ID.intValue()))
            .andExpect(jsonPath("$.receiveId").value(DEFAULT_RECEIVE_ID.intValue()))
            .andExpect(jsonPath("$.createdBy").value(DEFAULT_CREATED_BY))
            .andExpect(jsonPath("$.createdDate").value(DEFAULT_CREATED_DATE.toString()))
            .andExpect(jsonPath("$.lastModifiedBy").value(DEFAULT_LAST_MODIFIED_BY))
            .andExpect(jsonPath("$.lastModifiedDate").value(DEFAULT_LAST_MODIFIED_DATE.toString()));
    }

    @Test
    @Transactional
    void getNonExistingRoomUserBrokerChantMessage() throws Exception {
        // Get the roomUserBrokerChantMessage
        restRoomUserBrokerChantMessageMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    void putNewRoomUserBrokerChantMessage() throws Exception {
        // Initialize the database
        roomUserBrokerChantMessageRepository.saveAndFlush(roomUserBrokerChantMessage);

        int databaseSizeBeforeUpdate = roomUserBrokerChantMessageRepository.findAll().size();

        // Update the roomUserBrokerChantMessage
        RoomUserBrokerChantMessage updatedRoomUserBrokerChantMessage = roomUserBrokerChantMessageRepository
            .findById(roomUserBrokerChantMessage.getId())
            .get();
        // Disconnect from session so that the updates on updatedRoomUserBrokerChantMessage are not directly saved in db
        em.detach(updatedRoomUserBrokerChantMessage);
        updatedRoomUserBrokerChantMessage
            .message(UPDATED_MESSAGE)
            .status(UPDATED_STATUS)
            .messageType(UPDATED_MESSAGE_TYPE)
            .sendId(UPDATED_SEND_ID)
            .receiveId(UPDATED_RECEIVE_ID)
            .createdBy(UPDATED_CREATED_BY)
            .createdDate(UPDATED_CREATED_DATE)
            .lastModifiedBy(UPDATED_LAST_MODIFIED_BY)
            .lastModifiedDate(UPDATED_LAST_MODIFIED_DATE);
        RoomUserBrokerChantMessageDTO roomUserBrokerChantMessageDTO = roomUserBrokerChantMessageMapper.toDto(
            updatedRoomUserBrokerChantMessage
        );

        restRoomUserBrokerChantMessageMockMvc
            .perform(
                put(ENTITY_API_URL_ID, roomUserBrokerChantMessageDTO.getId())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomUserBrokerChantMessageDTO))
            )
            .andExpect(status().isOk());

        // Validate the RoomUserBrokerChantMessage in the database
        List<RoomUserBrokerChantMessage> roomUserBrokerChantMessageList = roomUserBrokerChantMessageRepository.findAll();
        assertThat(roomUserBrokerChantMessageList).hasSize(databaseSizeBeforeUpdate);
        RoomUserBrokerChantMessage testRoomUserBrokerChantMessage = roomUserBrokerChantMessageList.get(
            roomUserBrokerChantMessageList.size() - 1
        );
        assertThat(testRoomUserBrokerChantMessage.getMessage()).isEqualTo(UPDATED_MESSAGE);
        assertThat(testRoomUserBrokerChantMessage.getStatus()).isEqualTo(UPDATED_STATUS);
        assertThat(testRoomUserBrokerChantMessage.getMessageType()).isEqualTo(UPDATED_MESSAGE_TYPE);
        assertThat(testRoomUserBrokerChantMessage.getSendId()).isEqualTo(UPDATED_SEND_ID);
        assertThat(testRoomUserBrokerChantMessage.getReceiveId()).isEqualTo(UPDATED_RECEIVE_ID);
        assertThat(testRoomUserBrokerChantMessage.getCreatedBy()).isEqualTo(UPDATED_CREATED_BY);
        assertThat(testRoomUserBrokerChantMessage.getCreatedDate()).isEqualTo(UPDATED_CREATED_DATE);
        assertThat(testRoomUserBrokerChantMessage.getLastModifiedBy()).isEqualTo(UPDATED_LAST_MODIFIED_BY);
        assertThat(testRoomUserBrokerChantMessage.getLastModifiedDate()).isEqualTo(UPDATED_LAST_MODIFIED_DATE);
    }

    @Test
    @Transactional
    void putNonExistingRoomUserBrokerChantMessage() throws Exception {
        int databaseSizeBeforeUpdate = roomUserBrokerChantMessageRepository.findAll().size();
        roomUserBrokerChantMessage.setId(count.incrementAndGet());

        // Create the RoomUserBrokerChantMessage
        RoomUserBrokerChantMessageDTO roomUserBrokerChantMessageDTO = roomUserBrokerChantMessageMapper.toDto(roomUserBrokerChantMessage);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restRoomUserBrokerChantMessageMockMvc
            .perform(
                put(ENTITY_API_URL_ID, roomUserBrokerChantMessageDTO.getId())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomUserBrokerChantMessageDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomUserBrokerChantMessage in the database
        List<RoomUserBrokerChantMessage> roomUserBrokerChantMessageList = roomUserBrokerChantMessageRepository.findAll();
        assertThat(roomUserBrokerChantMessageList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void putWithIdMismatchRoomUserBrokerChantMessage() throws Exception {
        int databaseSizeBeforeUpdate = roomUserBrokerChantMessageRepository.findAll().size();
        roomUserBrokerChantMessage.setId(count.incrementAndGet());

        // Create the RoomUserBrokerChantMessage
        RoomUserBrokerChantMessageDTO roomUserBrokerChantMessageDTO = roomUserBrokerChantMessageMapper.toDto(roomUserBrokerChantMessage);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomUserBrokerChantMessageMockMvc
            .perform(
                put(ENTITY_API_URL_ID, count.incrementAndGet())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomUserBrokerChantMessageDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomUserBrokerChantMessage in the database
        List<RoomUserBrokerChantMessage> roomUserBrokerChantMessageList = roomUserBrokerChantMessageRepository.findAll();
        assertThat(roomUserBrokerChantMessageList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void putWithMissingIdPathParamRoomUserBrokerChantMessage() throws Exception {
        int databaseSizeBeforeUpdate = roomUserBrokerChantMessageRepository.findAll().size();
        roomUserBrokerChantMessage.setId(count.incrementAndGet());

        // Create the RoomUserBrokerChantMessage
        RoomUserBrokerChantMessageDTO roomUserBrokerChantMessageDTO = roomUserBrokerChantMessageMapper.toDto(roomUserBrokerChantMessage);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomUserBrokerChantMessageMockMvc
            .perform(
                put(ENTITY_API_URL)
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomUserBrokerChantMessageDTO))
            )
            .andExpect(status().isMethodNotAllowed());

        // Validate the RoomUserBrokerChantMessage in the database
        List<RoomUserBrokerChantMessage> roomUserBrokerChantMessageList = roomUserBrokerChantMessageRepository.findAll();
        assertThat(roomUserBrokerChantMessageList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void partialUpdateRoomUserBrokerChantMessageWithPatch() throws Exception {
        // Initialize the database
        roomUserBrokerChantMessageRepository.saveAndFlush(roomUserBrokerChantMessage);

        int databaseSizeBeforeUpdate = roomUserBrokerChantMessageRepository.findAll().size();

        // Update the roomUserBrokerChantMessage using partial update
        RoomUserBrokerChantMessage partialUpdatedRoomUserBrokerChantMessage = new RoomUserBrokerChantMessage();
        partialUpdatedRoomUserBrokerChantMessage.setId(roomUserBrokerChantMessage.getId());

        partialUpdatedRoomUserBrokerChantMessage
            .message(UPDATED_MESSAGE)
            .status(UPDATED_STATUS)
            .receiveId(UPDATED_RECEIVE_ID)
            .createdBy(UPDATED_CREATED_BY)
            .lastModifiedBy(UPDATED_LAST_MODIFIED_BY);

        restRoomUserBrokerChantMessageMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, partialUpdatedRoomUserBrokerChantMessage.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(partialUpdatedRoomUserBrokerChantMessage))
            )
            .andExpect(status().isOk());

        // Validate the RoomUserBrokerChantMessage in the database
        List<RoomUserBrokerChantMessage> roomUserBrokerChantMessageList = roomUserBrokerChantMessageRepository.findAll();
        assertThat(roomUserBrokerChantMessageList).hasSize(databaseSizeBeforeUpdate);
        RoomUserBrokerChantMessage testRoomUserBrokerChantMessage = roomUserBrokerChantMessageList.get(
            roomUserBrokerChantMessageList.size() - 1
        );
        assertThat(testRoomUserBrokerChantMessage.getMessage()).isEqualTo(UPDATED_MESSAGE);
        assertThat(testRoomUserBrokerChantMessage.getStatus()).isEqualTo(UPDATED_STATUS);
        assertThat(testRoomUserBrokerChantMessage.getMessageType()).isEqualTo(DEFAULT_MESSAGE_TYPE);
        assertThat(testRoomUserBrokerChantMessage.getSendId()).isEqualTo(DEFAULT_SEND_ID);
        assertThat(testRoomUserBrokerChantMessage.getReceiveId()).isEqualTo(UPDATED_RECEIVE_ID);
        assertThat(testRoomUserBrokerChantMessage.getCreatedBy()).isEqualTo(UPDATED_CREATED_BY);
        assertThat(testRoomUserBrokerChantMessage.getCreatedDate()).isEqualTo(DEFAULT_CREATED_DATE);
        assertThat(testRoomUserBrokerChantMessage.getLastModifiedBy()).isEqualTo(UPDATED_LAST_MODIFIED_BY);
        assertThat(testRoomUserBrokerChantMessage.getLastModifiedDate()).isEqualTo(DEFAULT_LAST_MODIFIED_DATE);
    }

    @Test
    @Transactional
    void fullUpdateRoomUserBrokerChantMessageWithPatch() throws Exception {
        // Initialize the database
        roomUserBrokerChantMessageRepository.saveAndFlush(roomUserBrokerChantMessage);

        int databaseSizeBeforeUpdate = roomUserBrokerChantMessageRepository.findAll().size();

        // Update the roomUserBrokerChantMessage using partial update
        RoomUserBrokerChantMessage partialUpdatedRoomUserBrokerChantMessage = new RoomUserBrokerChantMessage();
        partialUpdatedRoomUserBrokerChantMessage.setId(roomUserBrokerChantMessage.getId());

        partialUpdatedRoomUserBrokerChantMessage
            .message(UPDATED_MESSAGE)
            .status(UPDATED_STATUS)
            .messageType(UPDATED_MESSAGE_TYPE)
            .sendId(UPDATED_SEND_ID)
            .receiveId(UPDATED_RECEIVE_ID)
            .createdBy(UPDATED_CREATED_BY)
            .createdDate(UPDATED_CREATED_DATE)
            .lastModifiedBy(UPDATED_LAST_MODIFIED_BY)
            .lastModifiedDate(UPDATED_LAST_MODIFIED_DATE);

        restRoomUserBrokerChantMessageMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, partialUpdatedRoomUserBrokerChantMessage.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(partialUpdatedRoomUserBrokerChantMessage))
            )
            .andExpect(status().isOk());

        // Validate the RoomUserBrokerChantMessage in the database
        List<RoomUserBrokerChantMessage> roomUserBrokerChantMessageList = roomUserBrokerChantMessageRepository.findAll();
        assertThat(roomUserBrokerChantMessageList).hasSize(databaseSizeBeforeUpdate);
        RoomUserBrokerChantMessage testRoomUserBrokerChantMessage = roomUserBrokerChantMessageList.get(
            roomUserBrokerChantMessageList.size() - 1
        );
        assertThat(testRoomUserBrokerChantMessage.getMessage()).isEqualTo(UPDATED_MESSAGE);
        assertThat(testRoomUserBrokerChantMessage.getStatus()).isEqualTo(UPDATED_STATUS);
        assertThat(testRoomUserBrokerChantMessage.getMessageType()).isEqualTo(UPDATED_MESSAGE_TYPE);
        assertThat(testRoomUserBrokerChantMessage.getSendId()).isEqualTo(UPDATED_SEND_ID);
        assertThat(testRoomUserBrokerChantMessage.getReceiveId()).isEqualTo(UPDATED_RECEIVE_ID);
        assertThat(testRoomUserBrokerChantMessage.getCreatedBy()).isEqualTo(UPDATED_CREATED_BY);
        assertThat(testRoomUserBrokerChantMessage.getCreatedDate()).isEqualTo(UPDATED_CREATED_DATE);
        assertThat(testRoomUserBrokerChantMessage.getLastModifiedBy()).isEqualTo(UPDATED_LAST_MODIFIED_BY);
        assertThat(testRoomUserBrokerChantMessage.getLastModifiedDate()).isEqualTo(UPDATED_LAST_MODIFIED_DATE);
    }

    @Test
    @Transactional
    void patchNonExistingRoomUserBrokerChantMessage() throws Exception {
        int databaseSizeBeforeUpdate = roomUserBrokerChantMessageRepository.findAll().size();
        roomUserBrokerChantMessage.setId(count.incrementAndGet());

        // Create the RoomUserBrokerChantMessage
        RoomUserBrokerChantMessageDTO roomUserBrokerChantMessageDTO = roomUserBrokerChantMessageMapper.toDto(roomUserBrokerChantMessage);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restRoomUserBrokerChantMessageMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, roomUserBrokerChantMessageDTO.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomUserBrokerChantMessageDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomUserBrokerChantMessage in the database
        List<RoomUserBrokerChantMessage> roomUserBrokerChantMessageList = roomUserBrokerChantMessageRepository.findAll();
        assertThat(roomUserBrokerChantMessageList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void patchWithIdMismatchRoomUserBrokerChantMessage() throws Exception {
        int databaseSizeBeforeUpdate = roomUserBrokerChantMessageRepository.findAll().size();
        roomUserBrokerChantMessage.setId(count.incrementAndGet());

        // Create the RoomUserBrokerChantMessage
        RoomUserBrokerChantMessageDTO roomUserBrokerChantMessageDTO = roomUserBrokerChantMessageMapper.toDto(roomUserBrokerChantMessage);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomUserBrokerChantMessageMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, count.incrementAndGet())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomUserBrokerChantMessageDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomUserBrokerChantMessage in the database
        List<RoomUserBrokerChantMessage> roomUserBrokerChantMessageList = roomUserBrokerChantMessageRepository.findAll();
        assertThat(roomUserBrokerChantMessageList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void patchWithMissingIdPathParamRoomUserBrokerChantMessage() throws Exception {
        int databaseSizeBeforeUpdate = roomUserBrokerChantMessageRepository.findAll().size();
        roomUserBrokerChantMessage.setId(count.incrementAndGet());

        // Create the RoomUserBrokerChantMessage
        RoomUserBrokerChantMessageDTO roomUserBrokerChantMessageDTO = roomUserBrokerChantMessageMapper.toDto(roomUserBrokerChantMessage);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomUserBrokerChantMessageMockMvc
            .perform(
                patch(ENTITY_API_URL)
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomUserBrokerChantMessageDTO))
            )
            .andExpect(status().isMethodNotAllowed());

        // Validate the RoomUserBrokerChantMessage in the database
        List<RoomUserBrokerChantMessage> roomUserBrokerChantMessageList = roomUserBrokerChantMessageRepository.findAll();
        assertThat(roomUserBrokerChantMessageList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void deleteRoomUserBrokerChantMessage() throws Exception {
        // Initialize the database
        roomUserBrokerChantMessageRepository.saveAndFlush(roomUserBrokerChantMessage);

        int databaseSizeBeforeDelete = roomUserBrokerChantMessageRepository.findAll().size();

        // Delete the roomUserBrokerChantMessage
        restRoomUserBrokerChantMessageMockMvc
            .perform(delete(ENTITY_API_URL_ID, roomUserBrokerChantMessage.getId()).accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<RoomUserBrokerChantMessage> roomUserBrokerChantMessageList = roomUserBrokerChantMessageRepository.findAll();
        assertThat(roomUserBrokerChantMessageList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
